package io.renren.sf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.sf.dao.BookRoleDao;
import io.renren.sf.entity.BookRoleEntity;
import io.renren.sf.service.BookRoleService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Map;


@Service("bookRoleService")
public class BookRoleServiceImpl extends ServiceImpl<BookRoleDao, BookRoleEntity> implements BookRoleService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String roleName = (String)params.get("roleName");
        IPage<BookRoleEntity> page = this.page(
                new Query<BookRoleEntity>().getPage(params),
                new QueryWrapper<BookRoleEntity>()
                        .like(StringUtils.isNotBlank(roleName),"role_name", roleName)
        );

        return new PageUtils(page);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteBatch(Long[] roleIds) {
        //删除角色
        this.removeByIds(Arrays.asList(roleIds));
    }

}